//
//  trolleyCell.m
//  XDLookPic
//
//  Created by wanglong8889@126.com on 14-5-21.
//  Copyright (c) 2014年 XD-XY. All rights reserved.
//

#import "trolleyCell.h"
#import "UIImageView+WebCache.h"

@implementation trolleyCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 123)];
        _backView.userInteractionEnabled = YES;
        _backView.backgroundColor = [UIColor clearColor];
        [self addSubview:_backView];
        
        
        self.selectBtn = [SmallButton buttonWithType:UIButtonTypeCustom];
        _selectBtn.frame = CGRectMake(15, 50, 22, 22);
        [_selectBtn setBackgroundImage:[UIImage imageNamed:@"gouxuan_normal"] forState:UIControlStateNormal];
        [_selectBtn setBackgroundImage:[UIImage imageNamed:@"duihao_selected"] forState:UIControlStateSelected];
        _selectBtn.selected = YES;
        _selectBtn.smallCell = self;
        [self addSubview:_selectBtn];
        
        
        self.toumingBtn = [SmallButton buttonWithType:UIButtonTypeCustom];
        _toumingBtn.frame = CGRectMake(0, 30, 52, 62);
        _toumingBtn.smallCell = self;
        
        self.shopPicView = [[UIImageView alloc] initWithFrame:CGRectMake(_selectBtn.frame.origin.x+_selectBtn.frame.size.width+10, 18, 170/2, 172/2)];
        
        [self addSubview:_shopPicView];
        
        [self addSubview:_toumingBtn];
        
        self.shopContentLabel = [[UILabel alloc] initWithFrame:CGRectMake(_shopPicView.frame.origin.x+_shopPicView.frame.size.width+5, _shopPicView.frame.origin.y, 148, 35)];
        _shopContentLabel.backgroundColor = [UIColor clearColor];
        _shopContentLabel.font = [UIFont systemFontOfSize:14.0];
        _shopContentLabel.textColor = [UIColor blackColor];
        _shopContentLabel.text = @"优良 小型犬奶糕 离如期南沟粮食";
        _shopContentLabel.numberOfLines = 0;
        
        [self addSubview:_shopContentLabel];
        
        
        self.stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(_shopContentLabel.frame.origin.x,_shopContentLabel.frame.origin.y+_shopContentLabel.frame.size.height+3 , 30, 15)];
        _stateLabel.backgroundColor = [UIColor clearColor];
        _stateLabel.textColor = [UIColor grayColor];
        _stateLabel.text = @"价格:";
        _stateLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:12.0];
        
        [self addSubview:_stateLabel];
        
       UILabel *numLabel = [[UILabel alloc] initWithFrame:CGRectMake(_shopContentLabel.frame.origin.x,_stateLabel.frame.origin.y+_stateLabel.frame.size.height+6 ,30, 15)];
        numLabel.backgroundColor = [UIColor clearColor];
        numLabel.text = @"数量:";
        numLabel.textColor = [UIColor grayColor];
        numLabel.font = [UIFont systemFontOfSize:12.0];
        
        [self addSubview:numLabel];
        
        self.propertyLabel = [[UILabel alloc] initWithFrame:CGRectMake(_shopContentLabel.frame.origin.x,numLabel.frame.origin.y+numLabel.frame.size.height+7 , 170, 15)];
        _propertyLabel.backgroundColor = [UIColor clearColor];
        _propertyLabel.textColor = [UIColor grayColor];
        _propertyLabel.numberOfLines = 0;
        _propertyLabel.font = [UIFont systemFontOfSize:12.0];
        
        [self addSubview:_propertyLabel];
        
        
        self.numBtm = [SmallButton buttonWithType:UIButtonTypeCustom];
        _numBtm.frame = CGRectMake(numLabel.frame.origin.x+numLabel.frame.size.width+2,numLabel.frame.origin.y-2,46, 17);
        [_numBtm setBackgroundImage:[UIImage imageNamed:@"input_back"] forState:UIControlStateNormal];
        [_numBtm setTitle:@"1" forState:UIControlStateNormal];
        _numBtm.titleLabel.font = [UIFont systemFontOfSize:12.0];
        _numBtm.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [_numBtm setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _numBtm.contentEdgeInsets = UIEdgeInsetsMake(0, 3, 0, 0);
        _numBtm.smallCell = self;
        [self addSubview:_numBtm];
        
        
        
        self.pricLabel = [[UILabel alloc] initWithFrame:CGRectMake(_stateLabel.frame.origin.x+_stateLabel.frame.size.width+5,_stateLabel.frame.origin.y , 100, 15)];
        _pricLabel.backgroundColor = [UIColor clearColor];
        _pricLabel.textColor = [UIColor grayColor];
        _pricLabel.text = @"￥0.00";
        _pricLabel.font = [UIFont systemFontOfSize:13.0];
        
        [self addSubview:_pricLabel];
        

        self.arrowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(295,(_backView.frame.size.height-13)/2, 8, 12.5)];
       
        _arrowImageView.image = [UIImage imageNamed:@"arrow_cell"];
        [self addSubview:_arrowImageView];
        
        
        self.bgImageView = [[UIImageView alloc] init];
        _bgImageView.frame = CGRectMake(0, 0, 300, self.frame.size.height);
        [self setBackgroundView:_bgImageView];
        
        self.selectedImageView = [[UIImageView alloc] init];
        _selectedImageView.frame = CGRectMake(0, 0, 300,self.frame.size.height);
        [self setSelectedBackgroundView:_selectedImageView];
        
        
        self.totalLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,_propertyLabel.frame.origin.y+_propertyLabel.frame.size.height+5 , 310, 15)];
        _totalLabel.backgroundColor = [UIColor clearColor];
        _totalLabel.textColor = [UIColor grayColor];
        _totalLabel.textAlignment = NSTextAlignmentRight;
        _totalLabel.text = @"小计：￥0.00";
        _totalLabel.font = [UIFont systemFontOfSize:13.0];
        
        [self addSubview:_totalLabel];
        
        
        
    }
    return self;
}

- (void)awakeFromNib
{
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)layoutSubviews{
    
    [super layoutSubviews];
    self.shopContentLabel.text = self.shopTrolley.content;
    self.pricLabel.text = [NSString stringWithFormat:@"￥%.2f",[self.shopTrolley.price floatValue]];
    [self.shopPicView setImageWithURL:[NSURL URLWithString:self.shopTrolley.imageUrl] placeholderImage:[UIImage imageNamed:@"placeholderImg"]];
    self.propertyLabel.text = self.shopTrolley.goodsAttr;
    
    CGRect rect = self.propertyLabel.frame;
    
    rect.size.height = self.shopTrolley.attrHeight;
    
    self.propertyLabel.frame = rect;
    
    self.totalLabel.text = [NSString stringWithFormat:@"小计：￥%.2f",[self.shopTrolley.price floatValue]*[self.shopTrolley.number floatValue]];
    
    NSString *str = [NSString stringWithFormat:@"￥%.2f",[self.shopTrolley.price floatValue]*[self.shopTrolley.number floatValue]];
    
    self.totalLabel.attributedText = [XDTools getAcolorfulStringWithText1:@"小计:" Color1:[UIColor grayColor] Font1:[UIFont systemFontOfSize:13.0] Text2:str Color2:UIColorFromRGB(0Xdc4e2a) Font2:[UIFont systemFontOfSize:13.0] AllText:self.totalLabel.text];
    
    self.totalLabel.frame = CGRectMake(0,_propertyLabel.frame.origin.y+_propertyLabel.frame.size.height+5 , 310, 15);
    
    [self.numBtm setTitle:self.shopTrolley.number forState:UIControlStateNormal];
    
}
@end
